﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tests.DictionaryExtensions
{
    [TestClass]
    public class FrameworkExtensionsTest1
    {


        class Pet
        {
            public string Name { get; set; }
            public int Age { get; set; }
        }
        class Person
        {
            public string LastName { get; set; }
            public Pet[] Pets { get; set; }
        }





        [TestMethod]
        public void TestMethod1()
        {
            var dictionary = new Dictionary<string, string>() { 
                { "key1", "1" }, 
                { "key2", "1" }, 
                { "key3", "2" } 
            };
            var areAllConcerned = dictionary.All(kvp => kvp.Value.StartsWith("1"));
            Assert.IsFalse(areAllConcerned);


            dictionary = new Dictionary<string, string>() { 
                { "key1", "1" }, 
                { "key2", "1" }, 
                { "key3", "1" } 
            };
            areAllConcerned = dictionary.All(kvp => kvp.Value.StartsWith("1"));
            Assert.IsTrue(areAllConcerned);
        }





        [TestMethod]
        public void TestMethod2()
        {
            List<Person> people = new List<Person>  { 
               new Person {LastName = "Haas",
                           Pets = new Pet[] { 
                              new Pet {Name="Barley", Age=10 },
                              new Pet { Name="Boots", Age=14 },
                              new Pet { Name="Whiskers", Age=6 }}},
               new Person { LastName = "Fakhouri",
                            Pets = new Pet[] { 
                              new Pet { Name = "Snowball", Age = 1}}},
               new Person { LastName = "Antebi",
                            Pets = new Pet[] { 
                              new Pet { Name = "Belle", Age = 8} }},
               new Person { LastName = "Philips",
                            Pets = new Pet[] { 
                               new Pet { Name = "Sweetie", Age = 2},
                               new Pet { Name = "Rover", Age = 13}} }
             };

            // Determine which people have pets that are all older than 5.
            IEnumerable<string> names = from person in people
                                        where person.Pets.All(pet => pet.Age > 5)
                                        select person.LastName;

            Assert.AreEqual("Haas", names.ToArray()[0]);
            Assert.AreEqual("Antebi", names.ToArray()[1]);
        }




    }
}

